package com.itheima.controller;

import com.itheima.pojo.PageResult;
import com.itheima.pojo.Result;
import com.itheima.pojo.Student;
import com.itheima.pojo.StudentQueryParam;
import com.itheima.service.StudentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

@RestController
@Slf4j
@RequestMapping("/students")
public class StudentController {
    @Autowired
    private StudentService studentService;
/**
 * 学员分页查询
 */
    @GetMapping
    public Result Page(StudentQueryParam studentQueryParam){
        log.info("学生分页查询");
        PageResult<Student> pageResult=studentService.page(studentQueryParam);
        return Result.success(pageResult);
    }

    /**
     * 新增学员
     */
    @PostMapping
    public Result addstudent(@RequestBody Student student){
        log.info("新增学员");
        studentService.addstudent(student);
        return Result.success();
    }
    /**
     * 根据id查询学员
     */
    @GetMapping("/{id}")
    public Result findById(@PathVariable Integer id){
        Student student=studentService.findById(id);
        return Result.success(student);
    }
    /**
     * 修改学员
     */
    @PutMapping
    public Result update(@RequestBody Student student){
        studentService.update(student);
        return Result.success();
    }
    /**
     * 删除学院
     */
    @DeleteMapping("/{ids}")
    public Result delete(@PathVariable List<Integer> ids){
        studentService.deleteByIds(ids);
        return Result.success();
    }
    /**
     * 学员违纪
     */
    @PutMapping("/violation/{id}/{score}")
    public Result disciplinary(@PathVariable Integer id,@PathVariable Integer score){
        studentService.disById(id,score);
        return Result.success();
    }
}
